//
//  ORChannelViewController.m
//  News
//
//  Created by rimi on 2016/12/9.
//  Copyright © 2016年 dongfumei. All rights reserved.
//

#import "ORChannelViewController.h"

#import "ORNewsTableViewController.h"
#import <VTMagicController.h>

@interface ORChannelViewController () <VTMagicViewDataSource>


@property (nonatomic, strong) VTMagicController *controller;
@property (nonatomic, strong) NSArray *dataSource;

@end

@implementation ORChannelViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"频道";
    [self addChildViewController:self.controller];
    [self.view addSubview:self.controller.view];
    [self.controller.magicView reloadData];
}

#pragma mark - Custom initialize

-(NSArray<NSString *> *)menuTitlesForMagicView:(VTMagicView *)magicView{
    return @[@"头条", @"娱乐", @"体育", @"科技", @"军事", @"时尚"];
}

-(UIButton *)magicView:(VTMagicView *)magicView menuItemAtIndex:(NSUInteger)itemIndex{
    UIButton *menBtn = [magicView dequeueReusableItemWithIdentifier:@"itemId"];
    if (!menBtn) {
        menBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [menBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [menBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateSelected];
        menBtn.titleLabel.font = [UIFont systemFontOfSize:17];
    }
    return menBtn;
}

-(UIViewController *)magicView:(VTMagicView *)magicView viewControllerAtPage:(NSUInteger)pageIndex{
    return self.dataSource[pageIndex];
}

-(NSArray *)dataSource{
    if (!_dataSource) {
        NSArray *typeArr = @[@"top",@"yule",@"tiyu",@"junshi",@"keji",@"shishang"];
        NSMutableArray *array = [NSMutableArray array];
        for (int i = 0; i< typeArr.count; i++) {
            ORNewsTableViewController *newsVC = [[ORNewsTableViewController alloc]init];
            newsVC.type = typeArr[i];
            [array addObject:newsVC];
        }
        _dataSource = array;
    }
    return _dataSource;
}

-(VTMagicController *)controller{
    if (!_controller) {
        _controller = [[VTMagicController alloc]init];
        // 改变位置
        CGRect frame = _controller.view.frame;
//        frame.origin.y += 64;
        _controller.view.frame = frame;
        // 设置样式
        _controller.magicView.layoutStyle = VTLayoutStyleDivide;
        _controller.magicView.navigationColor = [UIColor whiteColor];
        // 滑调颜色
        _controller.magicView.sliderColor = MainColor;
        // 设置代理
        _controller.magicView.dataSource = self;
    }
    return _controller;
}

@end
